//商品详情展示
function showDetail(ordersId) {
    $.ajax({
        url : "orders/query",
        async : true,
        type : "GET",
        data : {
            "ordersId" : ordersId
        },
        // 成功后开启模态框
        success : queryDetail,
        error : function(res) {
            alert("订单信息获取失败");
        },
        dataType : "json"
    });
}
function queryDetail(res) {
    if(res.code!=0){
        alert(res.msg);
    }
    var model = res.data;
    $("#d_ordersId").text(model.ordersId);
    $("#d_ordersNo").text(model.ordersNo);
    $("#d_outTradeNo").text(model.outTradeNo);
    $("#d_expressNo").text(model.expressNo==null?'未发货':model.expressNo);
    $("#d_ordersRemark").text(model.ordersRemark);

    $("#d_goodsId").text(model.goodsId);
    $("#d_goodsName").text(model.goodsName);
    $("#d_goodsParam").text(model.goodsParam);
    $("#d_goodsPic").attr('src',model.goodsPic);

    $("#d_shopId").text(model.shopId);
    $("#d_shopName").text(model.shopName);

    $("#d_wxUserId").text(model.wxUserId);
    $("#d_nickname").text(model.nickname);

    $("#d_deliveryId").text(model.deliveryId);
    $("#d_deliveryCity").text(model.deliveryCity);
    $("#d_deliveryAddr").text(model.deliveryAddr);
    $("#d_deliveryPhone").text(model.deliveryPhone);
    $("#d_deliveryName").text(model.deliveryName);

    // 显示模态框
    $('#detailModal').modal('show');
}



//订单退款
function showRefund(ordersId) {
    if (confirm("是否确认发起退款？")) {
        $.ajax({
            type: 'POST',
            url: 'wxpay/refund/orders',
            dataType: 'json',
            data: {
                "ordersId": ordersId
            },
            error: function (request) {
                alert("未知错误，下架失败");
            },
            success: function (res) {
                if (res.code == 0) {
                    alert("退款发起成功");
                    window.location.reload();
                } else {
                    alert(res.msg);
                }
            }
        });
    }
}


//发货展示
function showSend(ordersId) {
    $("#ordersId").val(ordersId);
    $('#sendModal').modal('show');
}

//发货提交
$("#sendButton").click(function () {
    var formdata = new FormData(document.getElementById("sendForm"));
    $.ajax({
        type: "POST",
        url:"orders/send",
        data:formdata,	// 序列化表单值
        processData:false,
        contentType:false,
        error: function(request) {
            alert("未知错误！");
        },
        success: function(res) {
            if(res.code==0) {
                alert("发货成功！");
                window.location.reload();
            }else{
                alert(res.msg);
            }
        }
    });
});


//订单评价展示
function showComment(ordersId) {
    $.ajax({
        url : "orders/comment",
        async : true,
        type : "GET",
        data : {
            "ordersId" : ordersId
        },
        // 成功后开启模态框
        success : function(res){
            if(res.code!=0){
                alert(res.msg);
            }
            var model = res.data;
            $("#c_goodsComId").val(model.goodsComId);
            $("#c_ordersId").text(model.ordersId);
            $("#c_wxUserId").text(model.wxUserId);
            $("#c_goodsComText").text(model.goodsComText);
            $("#c_goodsComScore").text(model.goodsComScore);
            $("#c_goodsComTime").text(model.goodsComTime);
            // 显示模态框
            $('#commentModal').modal('show');
        },
        error : function(res) {
            alert("评价获取失败");
        },
        dataType : "json"
    });
}


//删除评价
$("#delComButton").click(function () {
    var goodsComId = $("#c_goodsComId").val();
    if (confirm("确认删除该评价？")) {
        $.ajax({
            type: "get",
            url:"orders/comment/delete",
            data:{
                "goodsComId" : goodsComId
            },
            error: function(request) {
                alert("未知错误！");
            },
            success: function(res) {
                if(res.code==0) {
                    alert("删除评价成功！");
                    window.location.reload();
                }else{
                    alert(res.msg);
                }
            }
        });
    }
});